#include<iostream>
#include<map>
#include<string>
using namespace std;
map<string, int>mp;
string s;
int n;
int main()
{
	int t;
	cin >> t;
	while (t--) {
		cin >> n;
		cin >> s;
		mp.clear();
		bool flag = 0;
		for (int i = 0; i < n; i++) {
			string temp = "";
			temp += s[i];
			temp += s[i + 1];
			if (mp[temp] != 0 && mp[temp] < i) {
				flag = 1;
				break;
			}
			if (mp[temp]) {
				mp[temp] = min(mp[temp], i + 1);
			}
			else {
				mp[temp] = i + 1;
			}
		}
		if (flag) {
			cout << "YES" << endl;
		}
		else {
			cout << "NO" << endl;
		}
	}
	return 0;
}